<?php

    class Controller_Ajax extends Controller {

      public function action_retrieveBlock($blockID,$useraction = null) {
            $mdlBlock = new Model_Blocks_Block();
            $block = $mdlBlock->getBlock($blockID);
            
            $view = View::factory('actions/view/blocktypes/'.$block['type'].$useraction);

            $view->blockSettings = $block;

            $this->request->response = $view;

        }

        public function action_setBlockPosition() {
            $mdlBlock = new Model_Blocks_Block();
            $mdlBlock->setBlockPosition($_POST['top'],$_POST['left'],$_POST['height'],$_POST['width'],$_POST['blockId']);
        }

        public function action_saveBlock($title,$type,$options = NULL){
            $mdlBlock = new Model_Blocks_Block();
            $blockID = $mdlBlock->saveBlock($title,$type,$options);

            $block = $mdlBlock->getBlock($blockID);

            $view = View::factory('actions/view/blocktypes/'.$block['type']);
            
            $view->blockSettings = array(
                'id' => $block['ID'],
                'title' => str_replace("'","\'",$block['title']),
                'type' => $block['type'],
                'setting' => $block['setting'],
                'position' => $block['position']
            );
            
            $this->request->response = $view;
        }

        public function action_editBlock($id){
            $mdlBlock = new Model_Blocks_Block();
            $blockID = $mdlBlock->editBlock($_POST['title'],$_POST['setting'],$id);
        }

        public function action_deleteBlock($id){
            $mdlBLock = new Model_Blocks_Block();
            $mdlBLock->deleteBlock($id);
        }
    }
?>
